package com.human.server.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.human.server.entity.Employees;
import com.human.server.model.R;
import com.human.server.model.response.EmployeeLoginResponse;
import com.human.server.service.EmployeesService;
import com.human.server.mapper.EmployeesMapper;
import org.springframework.stereotype.Service;

/**
* @author Admin
* @description 针对表【employees(员工表)】的数据库操作Service实现
* @createDate 2025-09-06 21:41:58
*/
@Service
public class EmployeesServiceImpl extends ServiceImpl<EmployeesMapper, Employees>
    implements EmployeesService{

    public R login(Employees employees) {

        Employees employee = baseMapper.selectOne(new LambdaQueryWrapper<Employees>()
                .eq(Employees::getPhone, employees.getPhone())
                .eq(Employees::getPassword, employees.getPassword()));

        if (employee == null) {
            return R.fail("登录失败");
        }

        EmployeeLoginResponse loginResponse = new EmployeeLoginResponse();
        StpUtil.login(employee.getId());
        loginResponse.setToken(StpUtil.getTokenValue());
        loginResponse.setEmployees(employee);
        return R.success(loginResponse);
    }
}




